home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / TriGrids / Sources / TriGridTextures.c < prev   
Encoding:
Text File  |  1996-02-20  |  4.0 KB  |  145 lines  |  [TEXT/MPCC]

  1. // routines to allow us to put texture maps on a parameterized group
  2. //
  3. //    03/23/95    rdd        added AddResourceTextureToGroup
  4.  
  5. #include "QD3D.h"
  6. #include "QD3DGroup.h"
  7. #include "QD3DShader.h"
  8.  
  9. #include <QuickDraw.h>
  10. #include <Resources.h>
  11. #include "PictRead.h"        // this is a library file from QD3D applications folder
  12. #include "Textures2.h"
  13.  
  14. TQ3Status AddTextureToGroup( TQ3GroupObject    theGroup, TQ3StoragePixmap *textureImage)
  15. {
  16.     TQ3TextureObject    textureObject;
  17.     TQ3GroupPosition position;
  18.     TQ3Object        firstObject;
  19.     
  20.     textureObject = Q3PixmapTexture_New(textureImage);
  21.     
  22.     if( textureObject ) {
  23.         if( Q3Object_IsType(theGroup, kQ3DisplayGroupTypeOrdered) == kQ3True) {
  24.             TQ3ShaderObject textureShader;
  25.             
  26.             Q3Group_GetFirstPositionOfType(
  27.                 theGroup,
  28.                 kQ3ShapeTypeShader, &position);    
  29.             
  30.             if( position ) {
  31.                 Q3Group_GetPositionObject(theGroup, position,    &firstObject);
  32.     
  33.                 if( Q3Object_IsType(firstObject, kQ3SurfaceShaderTypeTexture) == kQ3True) {
  34.                     TQ3TextureObject    oldTextureObject;
  35.                     TQ3StoragePixmap oldTextureImage;
  36.                     
  37.                     Q3TextureShader_GetTexture(firstObject, &oldTextureObject);
  38.                     Q3PixmapTexture_GetPixmap(oldTextureObject, &oldTextureImage);
  39.                     
  40.                     Q3Object_Dispose(oldTextureObject);
  41.                     Q3TextureShader_SetTexture(firstObject, textureObject);
  42.                     Q3Object_Dispose(textureObject);
  43.                 } else {
  44.                     textureShader = Q3TextureShader_New(textureObject);
  45.                     if( textureShader ) {
  46.                         Q3Object_Dispose(textureObject);
  47.                         Q3Group_SetPositionObject(theGroup, position, textureShader);
  48.                         Q3Object_Dispose(textureShader);
  49.                     } else {
  50.                         return(kQ3Failure);
  51.                     }
  52.                 }
  53.             } else {
  54.                 textureShader = Q3TextureShader_New(textureObject);
  55.                 if( textureShader ) {
  56.                     Q3Object_Dispose(textureObject);
  57.                     Q3Group_AddObject(theGroup, textureShader);
  58.                     Q3Object_Dispose(textureShader);
  59.                 } else {
  60.                     return(kQ3Failure);
  61.                 }
  62.             }
  63.         } else if( Q3Object_IsType(theGroup, kQ3GroupTypeDisplay) == kQ3True) {
  64.             Q3Group_GetFirstPosition(theGroup, &position);
  65.     
  66.             Q3Group_GetPositionObject(theGroup, position,    &firstObject);
  67.     
  68.             if( Q3Object_IsType(firstObject, kQ3SurfaceShaderTypeTexture) == kQ3True) {
  69.                 TQ3TextureObject    oldTextureObject;
  70.                 TQ3StoragePixmap oldTextureImage;
  71.                         
  72.                 Q3TextureShader_GetTexture(firstObject, &oldTextureObject);
  73.                 Q3PixmapTexture_GetPixmap(oldTextureObject, &oldTextureImage);
  74.                 
  75.                 Q3Object_Dispose(oldTextureObject);
  76.                 Q3TextureShader_SetTexture(firstObject, textureObject);
  77.                 Q3Object_Dispose(textureObject);
  78.             } else {
  79.                 TQ3ShaderObject textureShader;
  80.                 
  81.                 textureShader = Q3TextureShader_New(textureObject);
  82.                 Q3Object_Dispose(textureObject);
  83.                 //Q3Group_SetPositionObject(theGroup, position, theDocument->textureShader);
  84.                 Q3Group_AddObjectBefore(theGroup, position, textureShader);
  85.                 Q3Object_Dispose(textureShader);
  86.             }
  87.             
  88.             Q3Object_Dispose(firstObject);
  89.         }
  90.     return(kQ3Success);
  91.     } else {
  92.         return(kQ3Failure);
  93.     }
  94. }
  95.  
  96. void PictureFileToPixmap( TQ3StoragePixmap *bMap )
  97. {
  98.     PicHandle             thePicture = nil;
  99.     
  100.     if((thePicture = GetPICTFile()) != NULL ) {
  101.     
  102.         LoadMapPICT( thePicture, 
  103.                      0L,
  104.                      (unsigned long)((**thePicture).picFrame.right - (**thePicture).picFrame.left),
  105.                      (unsigned long)((**thePicture).picFrame.bottom - (**thePicture).picFrame.top),
  106.                      bMap)    ;
  107.         
  108.     }
  109. }
  110.  
  111. void TextureGroup( TQ3GroupObject    theGroup)
  112. {
  113.     TQ3StoragePixmap         myMap ;
  114.     
  115.     PictureFileToPixmap( &myMap ) ;
  116.     if( myMap.image != NULL )
  117.         AddTextureToGroup( theGroup, &myMap ) ;
  118. }
  119.  
  120.  
  121. void AddResourceTextureToGroup( short pictResID, TQ3GroupObject    theGroup )
  122. {
  123.     TQ3StoragePixmap     bMap;
  124.     PicHandle             thePicture = nil;
  125.  
  126.     if (theGroup == NULL)
  127.         return;
  128.  
  129.     if((thePicture = (PicHandle) GetResource('PICT', pictResID)) != NULL ) {
  130.  
  131.         HLock((Handle) thePicture);
  132.         LoadMapPICT( thePicture, 
  133.                      0L,
  134.                      (unsigned long)((**thePicture).picFrame.right - (**thePicture).picFrame.left),
  135.                      (unsigned long)((**thePicture).picFrame.bottom - (**thePicture).picFrame.top),
  136.                      &bMap)    ;
  137.  
  138.         if( bMap.image != NULL )
  139.             AddTextureToGroup( theGroup, &bMap ) ;
  140.  
  141.         HUnlock((Handle) thePicture);
  142.         ReleaseResource((Handle) thePicture);
  143.     }
  144. }
  145.